#!/usr/bin/env bash

formatter=gofmt
hash goimports 2>/dev/null && {
  formatter=goimports
}

# don't run gofmt in these directories
ignored=(/bin/ /docs/ /log/ /man/ /tmp/ /vendor/ /rpm/ /docker/ /debian/)
for i in */ ; do
  if [[ ! ${ignored[*]} =~ "/$i" ]]; then
    $formatter -w -l "$@" "${i%?}"
  fi
done

msg=`script/lint`
if [ $? -ne 0 ];
then
  echo "$msg"
  exit 1
fi
